package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;



    /**
     * 获取排行榜
     * /api/search/albumInfo/findRankingList/{category1Id}/{dimension}
     * @param category1Id
     * @param dimension
     * @return
     */
    @GetMapping("/albumInfo/findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndex>> findRankingList(@PathVariable Long category1Id, @PathVariable String dimension){
        List<AlbumInfoIndex> list = searchService.findRankingList(category1Id, dimension);
        return Result.ok(list);
    }

    /**
     * 更新排榜，并存入redis中
     * /api/search/albumInfo/updateLatelyAlbumRanking
     * @return
     */
    @GetMapping("/albumInfo/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking() {
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }
    /**
     * 关键字自动补全
     * /api/search/albumInfo/completeSuggest/{keyword}
     * @param keyword
     * @return
     */
    @GetMapping("/albumInfo/completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable String keyword) {
        List<String> list = searchService.completeSuggest(keyword);
        return Result.ok(list);
    }



    /**
     * 专辑检索
     * /api/search/albumInfo
     * @param albumIndexQuery
     * @return
     */
    @Operation(summary = "ES站内检索，支持关键字、分类、标签条件分页检索，结果高亮")
    @PostMapping("/albumInfo")
    public Result<AlbumSearchResponseVo> albumInfo(@RequestBody AlbumIndexQuery albumIndexQuery) {
        AlbumSearchResponseVo albumSearchResponseVo = searchService.albumInfo(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }


    /**
     * /api/search/albumInfo/channel/{category1Id}
     * 查询指定一级分类下热门排行专辑
     * @param category1Id
     * @return
     */
    @Operation(summary = "查询指定一级分类下热门排行专辑")
    @GetMapping("/albumInfo/channel/{category1Id}")
    public Result<List<Map<String, Object>>> albumInfoChannel(@PathVariable Long category1Id) {
        List<Map<String, Object>> list = searchService.albumInfoChannel(category1Id);
        return Result.ok(list);
    }
}

